package cc.eguid.tools.ui;

import cc.eguid.tools.utils.Utils;

import javax.swing.*;
import java.awt.*;
import java.io.File;

/**
 * 窗口实例
 */
public class RemoteAssistance extends JFrame {
    protected static final int DEFAULT_PORT = 18080;
    protected static final int DEFAULT_FILE_TRANSFER_PORT = 18081;
    private JTabbedPane tabbedPane;
    private ServerPanel serverPanel;
    private ClientPanel clientPanel;

    //logo配置
    private static final String LOGO_RESOURCE = "/logo.png";


    public RemoteAssistance() {
        super("Java远程桌面连接控制工具-关注微信公众号：eguid");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(1000, 600);
        setMinimumSize(new Dimension(1000,600));
        setLocationRelativeTo(null);

        tabbedPane = new JTabbedPane();
        serverPanel = new ServerPanel();
        clientPanel = new ClientPanel();

        tabbedPane.addTab("\uD83D\uDDA5 服务端", serverPanel);
        tabbedPane.addTab("\uD83D\uDD17 客户端", clientPanel);

        add(tabbedPane);
        setWindowIcon();//设置图标
        setVisible(true);
    }

    // 替换原来的setWindowIcon方法
    private boolean setWindowIcon() {
        // 优先尝试从资源加载
        ImageIcon icon= Utils.loadIconFromResource(LOGO_RESOURCE);
        if (icon != null) {
            setIconImage(icon.getImage());
            return true;
            // 尝试从外部文件加载
        }else if (loadIconFromFile(LOGO_RESOURCE)) {
            return true;
        }
        return false;
    }

    // 从文件系统加载图标
    private boolean loadIconFromFile(String filePath) {
        try {
            File iconFile = new File(filePath);
            if (iconFile.exists()) {
                ImageIcon icon = new ImageIcon(filePath);
                setIconImage(icon.getImage());
                return true;
            }
        } catch (Exception e) {
            System.err.println("加载图标文件失败: " + filePath + " - " + e.getMessage());
        }
        return false;
    }


}




